<?php
namespace app\index\controller;

use think\Config;

class Index
{
    public function index()
    {
        $weixin = Config::get('weixin');
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=".$weixin['grant_type'].
            '&appid='.$weixin['appid']."&secret=".$weixin['secret'];

        echoJson(1,'成功',$this->http_curl($url));
    }

    public function http_curl($url,$type='get',$res='json',$arr='')
    {
        //1.初始化curl
        $ch = curl_init();
        //2.设置curl的参数
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        if ($type == 'post') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
        }
        //3.采集
        $output = curl_exec($ch);
        //4.关闭
        curl_close($ch);
//        if ($res == 'json') {
//            return json_decode($output, true);
//        }
       return $output;
    }
}
